# ---------------------------------------------------------------------------
# Author: Keith Hill
# Desc:   Replacement DIR functions.  These sort based on various criteria.
#         The default DIR replacement sorts folders first and then by name.
#         DIRS sorts folders first and then by the file's size.
#         DIRT sorts folders first and then by the file's last write time.
#         DIRD sorts folders first and then by the file's last write time.
# Date:   Nov 18, 2006
# Site:   http://www.codeplex.com/PowerShellCX
# Usage:  In your profile place the following command:
#  
#         . "$Env:PscxHome\Profile\Dir.ps1"
# ---------------------------------------------------------------------------
Remove-Item alias:dir -Force -ErrorAction:SilentlyContinue

$__PscxSortContainer = @{ E={ $_.PSIsContainer }; Asc=0 }
$__PscxSortTime      = @{ E={ $_.LastWriteTime }; Asc=1 } 
$__PscxSortLength    = @{ E={ $_.Length };        Asc=1 } 
$__PscxSortName      = @{ E={ $_.Name };          Asc=1 } 

function dir([string[]]$path) { 
	get-childitem -Path $path -ea SilentlyContinue -Force:$PscxShowHiddenItemsPreference `
	| sort $__PscxSortContainer, $__PscxSortName
}

function dirw([string[]]$path) { 
	get-childitem -Path $path -ea SilentlyContinue -Force:$PscxShowHiddenItemsPreference `
	| sort $__PscxSortContainer, $__PscxSortName | format-wide -auto
} 

function dirs([string[]]$path) { 
	get-childitem -Path $path -ea SilentlyContinue -Force:$PscxShowHiddenItemsPreference `
	| sort $__PscxSortContainer, $__PscxSortLength
} 

function dirt([string[]]$path) { 
	get-childitem -Path $path -ea SilentlyContinue -Force:$PscxShowHiddenItemsPreference `
	| sort $__PscxSortContainer, $__PscxSortTime
} 

function dird([string[]]$path) { 
	get-childitem -Path $path -ea SilentlyContinue -Force:$PscxShowHiddenItemsPreference `
	| where {$_.PSIsContainer} | sort Name
}

